Telegram Group & Telegram Channel
Превью из длинного текста

Допустим, у нас есть какой-то длинный текст в виде строки и надо сделать превью этого текста, например, для сайта. Первое, что приходит на ум – использовать слайсинг строк.

Но, как видите, текст оборвался на полуслове, поэтому такой вариант отпадает. Такую проблему хорошо решает метод shorten из модуля textwrap.

Первым аргументом передается строка, вторым указываем количество символов, которое должен содержать результат. Также третьим аргументом можно передать заготовку, которая будет вставляться в конце обрезанной строки.

#строки #textwrap



tg-me.com/python_academy/898
Create:
Last Update:

Превью из длинного текста

Допустим, у нас есть какой-то длинный текст в виде строки и надо сделать превью этого текста, например, для сайта. Первое, что приходит на ум – использовать слайсинг строк.

Но, как видите, текст оборвался на полуслове, поэтому такой вариант отпадает. Такую проблему хорошо решает метод shorten из модуля textwrap.

Первым аргументом передается строка, вторым указываем количество символов, которое должен содержать результат. Также третьим аргументом можно передать заготовку, которая будет вставляться в конце обрезанной строки.

#строки #textwrap

BY Python Academy




Share with your friend now:
tg-me.com/python_academy/898

View MORE
Open in Telegram


Python Academy Telegram | DID YOU KNOW?

Date: |

Should You Buy Bitcoin?

In general, many financial experts support their clients’ desire to buy cryptocurrency, but they don’t recommend it unless clients express interest. “The biggest concern for us is if someone wants to invest in crypto and the investment they choose doesn’t do well, and then all of a sudden they can’t send their kids to college,” says Ian Harvey, a certified financial planner (CFP) in New York City. “Then it wasn’t worth the risk.” The speculative nature of cryptocurrency leads some planners to recommend it for clients’ “side” investments. “Some call it a Vegas account,” says Scott Hammel, a CFP in Dallas. “Let’s keep this away from our real long-term perspective, make sure it doesn’t become too large a portion of your portfolio.” In a very real sense, Bitcoin is like a single stock, and advisors wouldn’t recommend putting a sizable part of your portfolio into any one company. At most, planners suggest putting no more than 1% to 10% into Bitcoin if you’re passionate about it. “If it was one stock, you would never allocate any significant portion of your portfolio to it,” Hammel says.

How to Buy Bitcoin?

Most people buy Bitcoin via exchanges, such as Coinbase. Exchanges allow you to buy, sell and hold cryptocurrency, and setting up an account is similar to opening a brokerage account—you’ll need to verify your identity and provide some kind of funding source, such as a bank account or debit card. Major exchanges include Coinbase, Kraken, and Gemini. You can also buy Bitcoin at a broker like Robinhood. Regardless of where you buy your Bitcoin, you’ll need a digital wallet in which to store it. This might be what’s called a hot wallet or a cold wallet. A hot wallet (also called an online wallet) is stored by an exchange or a provider in the cloud. Providers of online wallets include Exodus, Electrum and Mycelium. A cold wallet (or mobile wallet) is an offline device used to store Bitcoin and is not connected to the Internet. Some mobile wallet options include Trezor and Ledger.

Python Academy from cn


Telegram Python Academy
FROM USA